import pygame,math
from vector import vector
def getCollision(obj,obj2):
    if obj.getPos()[0]>=obj2.getPos()[0] and obj.getPos()[1]<=obj2.getPos()[0]+obj2.getWidth() and obj.getPos()[1]>=obj2.getPos()[1] and obj.getPos()[1]<=obj2.getPos()[1]+obj2.getHeight():
        return True
    else:
        return False
class sprite:
    def __init__(self,images,surface):
        self.frame = []
        self.frameNumber = 0
        self.a = False
        self.av = (0,0,0)
        self.angle = 0
        for name in images:
            self.frame.append(i_object(name,surface))
    def scale(self,sc):
        for image in self.frame:
            image.scale(sc[0],sc[1])
    def setAlpha(self,alphaV):
        self.a = True
        self.av = alphaV
    def getLenght(self):
        return len(self.frame)-1
    def setFrame(self,n):
        self.frameNumber = n-1
    def setAngle(self,ang):
        self.angle = ang
        self.frame[self.frameNumber].rotate(ang)
    def draw(self,pos):
        if self.a:
            self.frame[self.frameNumber].alpha()
        self.frame[self.frameNumber].rotate(self.angle)
        self.frame[self.frameNumber].draw(pos)
class polygon:
    def __init__(self,surface,pointList = [],width = 1,color = (0,0,0)):
        self.pointList = pointList
        self.body = pygame.draw.polygon(surface,color,pointList,width)
    def draw(self,pos):
        for point in self.pointList:
            point = (point[0]+(point[0]-pos.get()[0]),point[1]+(point[1]-pos.get()[1]))
        self.body = pygame.draw.polygon(surface,color,pointList,width)
class i_object:
    def __init__(self,i_path,surface):
        self.i_object = pygame.image.load(i_path)
        self.i_object.convert()
        self.rect = self.i_object.get_rect()
        self.surface = surface
        self.original = self.i_object.copy()
    def scale(self,width,height):
        self.i_object = pygame.transform.scale(self.i_object,(width,height))
        self.original = self.i_object.copy()
    def draw(self,vec):
        self.surface.blit(self.i_object,vec.get())
    def rotate(self,r):
        orig = self.i_object.copy()
        orig = orig.get_rect()
        rot_image = pygame.transform.rotate(self.original,r)
        self.rect = self.original.get_rect()
        rot_rect = orig.copy()
        rot_rect.center = rot_image.get_rect().center
        rot_image = rot_image.subsurface(rot_rect).copy()
        self.i_object = rot_image
    def lock(self):
        self.i_object.lock()
    def unlock(self):
        self.i_object.unlock()
    def alpha(self):
        self.i_object.set_colorkey(self.i_object.get_at((0,0)))
class s_object:
    def __init__(self,window,color,width,height):
        self.width = width
        self.height = height
        self.windowSurface = window
        self.object = pygame.Surface((width,height))
        self.object.fill(color)
        self.pos = vector(200000000,200000000)
    def color(self,color):
        self.object.fill(color)
    def alpha(self,val):
        self.object.set_alpha(val)
    def draw(self,vec):
        self.pos = vec
        self.windowSurface.blit(self.object,vec.get())
    def getWidth(self):
        return self.width
    def getHeight(self):
        return self.height
    def getPos(self):
        return self.pos.get()
    def returnRect(self):
        return self.object.get_rect()
class r_object:
    def __init__(self,surface,color,width,height):
        self.surface = surface
        self.color = color
        self.width = width
        self.height = height
        vec = vector(200000,200000)
        self.vec = vector(200000,200000)
        self.object = pygame.draw.rect(self.surface,self.color,(vec.get()[0],vec.get()[1],self.width,self.height))
    def changeColor(self,color):
        self.color = color
    def draw(self,vec):
        self.object = pygame.draw.rect(self.surface,self.color,(vec.get()[0],vec.get()[1],self.width,self.height))
        self.vec = vec
    def getWidth(self):
        return self.width
    def getHeight(self):
        return self.height
    def getVector(self):
        return self.vec
    def getPos(self):
        return self.vec.get()
    def returnRect(self):
        return self.object
class text:
    def __init__(self,screen,text,color):
        self.screen = screen
        self.text = text
        self.color = color
        self.size = 20
        self.font = None
    def color(self,color):
        self.color = color
    def size(self,size):
        self.size = size
    def draw(self,vec):
        font = pygame.font.SysFont("Courier New",self.size)
        ren = font.render(self.text,1,self.color)
        self.font = font
        self.screen.blit(ren,vec.get())
    def getWidth(self):
        if self.font != None:
            return self.font.size(self.text)[0]
        else:
            return 0
class line:
    def __init__(self,screen,color,start_pos,end_pos):
        self.width = 1
        self.color = color
        self.screen = screen
        self.body = pygame.draw.line(screen,self.color, start_pos.get(), end_pos.get(), self.width)
    def color(self,color):
        self.color = color
    def width(self,val):
        self.width = val
    def draw(self,start_pos,end_pos):
        self.pos = start_pos
        self.body = pygame.draw.line(self.screen,self.color, start_pos.get(), end_pos.get(), self.width)
    def returnRect(self):
        return self.body
    def getPos(self):
        return self.pos.get()
